import axios from "axios";

const deviceBaseUrl= 'http://localhost:8082';
const deviceRequest={
    loadDevices(device,callBack){
        let url = deviceBaseUrl + "/device/list?";
        if(device){
            if(device.deviceName){
                url += "&deviceName=" + device.deviceName;
            }
            if(device.deviceStatus){
                url += "&deviceStatus=" + device.deviceStatus;
            }
        }
        axios.get(url)
            .then(res=>{
                callBack(res.data);
            })
    },
    insertDevice(device,callBack){
        let url = deviceBaseUrl + "/device/insert";
        axios.post(url,device)
            .then(res=>{
                callBack(res.data);
            })
    },
    updateDeviceById(device,callBack){
        let url  = deviceBaseUrl + "/device/update";
        axios.put(url,device)
            .then(res=>{
                callBack(res.data);
            })
    },
    selectDeviceById(deviceId,callBack){
        let url = deviceBaseUrl + "/device/selectById?deviceId=" + deviceId;
        axios.get(url)
            .then(res=>{
                callBack(res.data);
            })
    },
    deleteDeviceById(deviceId,callBack){
        let url = deviceBaseUrl + "/device/delete?deviceId=" + deviceId;
        axios.delete(url)
            .then(res=>{
                callBack(res.data);
            })
    }
}
export default deviceRequest;